package com.regexp.util;

import com.regexp.constant.RegexpConstants;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexpUtil {

    /**
     * 通用正则验证:默认
     */
    public static boolean validateRegExp(String content, String regexp) {
        if (content==null || content.length()==0 || regexp==null || regexp.length()==0) {
            return false;
        }
        Pattern pattern = Pattern.compile(regexp);
        if (pattern.matcher(content).matches()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 通用正则验证:不区分大小写
     */
    public static boolean validateRegExpNoneCaseSensitive(String content, String regexp) {
        if (content==null || content.length()==0 || regexp==null || regexp.length()==0) {
            return false;
        }
        Pattern pattern = Pattern.compile(regexp,Pattern.CASE_INSENSITIVE);
        if (pattern.matcher(content).matches()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 正则过滤方法
     */
    public static String stringFilter(String content,String regexp){
        if (content==null || content.length()==0 || regexp==null || regexp.length()==0) {
            return null;
        }
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(content);
        return matcher.replaceAll("").trim();
    }

    public static void main(String[] args) {

    }
}
